﻿namespace Devonline.Entity;

/// <summary>
/// 证件, 字符串表达式的默认实现
/// </summary>
[Table("credential"), DisplayName("证件")]
public class Credential : Credential<string>, IEntitySet, IEntitySetWithCreate
{
    /// <summary>
    /// 证件的附加信息
    /// </summary>
    public virtual ICollection<CredentialAdditional>? Additionals { get; set; }
    /// <summary>
    /// 通用附件集合, NotMapped Attachments 用于记录实体对象上上传的附件
    /// </summary>
    [NotMapped]
    public virtual ICollection<Attachment>? Attachments { get; set; }
}

/// <summary>
/// 证件附加信息
/// </summary>
[Table("credential_additional"), DisplayName("证件附加信息")]
public class CredentialAdditional : CredentialAdditional<string>, IAdditional, IEntitySet, IEntitySetWithCreate
{
    /// <summary>
    /// 证件
    /// </summary>
    public virtual Credential? Additional { get; set; }
}

/// <summary>
/// 证件
/// </summary>
[Table("credential"), DisplayName("证件")]
public abstract class Credential<TKey> : EntitySetWithCreate<TKey>, IEntitySet<TKey>, IEntitySetWithCreate<TKey> where TKey : IConvertible
{
    /// <summary>
    /// 证件所有者编号, 证件所有者, 可以是用户或者组织, 具体子类实现时, 可根据实际情况, 在只有一种形式时直接使用外键
    /// </summary>
    [Column("owner_id"), DisplayName("证件所有者编号"), Required, MaxLength(36), Excel]
    public virtual TKey? OwnerId { get; set; }
    /// <summary>
    /// 证件类型
    /// </summary>
    [Column("type", TypeName = "VARCHAR(36)"), DisplayName("证件类型"), Required, Excel]
    public virtual CredentialType Type { get; set; }
    /// <summary>
    /// 证件上名字
    /// </summary>
    [Column("name"), DisplayName("姓名"), Required, MaxLength(256), Excel]
    public virtual string? Name { get; set; }
    /// <summary>
    /// 证件号码
    /// </summary>
    [Column("code"), DisplayName("证件号码"), MaxLength(256), Unique, Excel]
    public virtual string? Code { get; set; }
    /// <summary>
    /// 签发机关
    /// </summary>
    [Column("issued_by"), DisplayName("签发机关"), MaxLength(36), Excel]
    public virtual string? IssuedBy { get; set; }
    /// <summary>
    /// 有效期始
    /// </summary>
    [Column("start_date"), DisplayName("有效期始"), Excel]
    public virtual DateTime? StartDate { get; set; }
    /// <summary>
    /// 有效期至
    /// </summary>
    [Column("end_date"), DisplayName("有效期至"), Excel]
    public virtual DateTime? EndDate { get; set; }
    /// <summary>
    /// 证件照片
    /// </summary>
    [Column("image"), DisplayName("证件照片"), MaxLength(128), BusinessType(IsAttachment = true), Excel]
    public virtual string? Image { get; set; }
    /// <summary>
    /// 证件头像照片
    /// </summary>
    [Column("head_image"), DisplayName("证件头像照片"), MaxLength(128), Excel]
    public virtual string? HeadImage { get; set; }
    /// <summary>
    /// 备注说明
    /// </summary>
    [Column("description"), DisplayName("备注说明"), MaxLength(256), Excel]
    public virtual string? Description { get; set; }
}

/// <summary>
/// 证件附加信息
/// </summary>
[Table("credential_additional"), DisplayName("证件附加信息")]
public abstract class CredentialAdditional<TKey> : Additional<TKey>, IAdditional<TKey>, IEntitySet<TKey>, IEntitySetWithCreate<TKey> where TKey : IConvertible { }